<?php
class Paginator {
	public function __construct()
	{
		
	}
	
	public function paginator($section, $mod, $tplfile, $cat_id,$where)
	{
		CommonFunc::loadFile("model/Product.php");
		$modProduct = new FrontProduct();
		$request = CommonFunc::getRequest();
		//$savecartid = $request['savecartid'];
		if(isset($request['savecartid']))
		{
			$_SESSION['savecartid'] = $request['savecartid'];
		} else {
			$_SESSION['savecartid'] = "";
		}
		
		$module_arr = $_SERVER['QUERY_STRING']; 
		$module_arr = explode("/", $module_arr);
		$module = $module_arr[0];
		$param1 = $module_arr[1];
		$param2 = $module_arr[2];
		$param3 = $module_arr[3];
		$param4 = $module_arr[4];
		
		switch ($section)
		{
			case "category" :
				$product_count = $modProduct->getProductsByCategory($cat_id, "",$where);
				$pagenum = $param4;
				break;
				
			case "subcategory" :
				$product_count = $modProduct->getProductsBySubCategory($cat_id, "",$where);
				$pagenum = $param4;
				break;	
				
			case "products" :
				$product_count = $modProduct->getProduct();
				$pagenum = $param1;
				break;
		}
		
		//$pagenum = $_GET['pagenum'];
		
		if (!(isset($pagenum))) 
		{		
			$pagenum = 1; 		
		} 
		
		
		$rows = count($product_count);
		$last = ceil($rows/ITEMPERPAGE); 
		
		if ($pagenum < 1) { 		
			$pagenum = 1; 		
		} elseif ($pagenum > $last) { 		
			$pagenum = $last; 		
		} 
		
		$max = 'LIMIT ' .($pagenum - 1) * ITEMPERPAGE .',' .ITEMPERPAGE; 
		
		switch ($section)
		{
			case "category" :
				$item_arr = $modProduct->getProductsByCategory($cat_id, $max,$where);
				break;
				
			case "subcategory" :
				$item_arr = $modProduct->getProductsBySubCategory($cat_id, $max,$where);
				break;	
				
			case "products" :
				$product_arr = $modProduct->getProduct($max);
				break;
		}
		
		//$qry_str = $_SERVER['QUERY_STRING'];
		

                     // CommonFunc::loadFile("model/Product.php");
			//$modProduct = new FrontProduct();
                        $request = CommonFunc::getRequest();
			$brandarr = $modProduct->getbrandsforprintesearch($request);
                        $prodbybrandarr = $modProduct->getprodbybrands($request);
                       
		
		include SITETPL . $mod . "/" . $tplfile . ".phtml";

	}
}
?>
